package databaseLayer;

import java.util.List;
import model.ReservedSeat;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;

import util.HibernateUtil;

public class ReservedSeat_db {

    public List<String> selectReservedSeatNosByHouseId(String houseId) {
        Session session = null;
        Transaction tx = null;
        try {
            session = HibernateUtil.getThreadLocalSession();
            tx = session.beginTransaction();
            Query query = session.createQuery("select rs.seatNo from ReservedSeat as rs where houseId=:houseId");
            query.setString("houseId", houseId);
            List<String> result = query.list();
            return result;
        } catch (Exception e) {
            tx.rollback();
        } finally {
            if (session != null) {
                HibernateUtil.closeSession();
            }
        }
        return null;
    }

    public List<ReservedSeat> selectAllReservedSeats() {
        Session session = null;
        Transaction tx = null;
        try {
            session = HibernateUtil.getThreadLocalSession();
            tx = session.beginTransaction();
            Query query = session.createQuery("from ReservedSeat");
            List<ReservedSeat> result = query.list();
            return result;
        } catch (Exception e) {
            tx.rollback();
        } finally {
            if (session != null) {
                HibernateUtil.closeSession();
            }
        }
        return null;
    }

    private ReservedSeat_db() {
    }
    private static ReservedSeat_db instance;

    public static ReservedSeat_db getInstance() {
        if (instance == null) {
            instance = new ReservedSeat_db();
        }
        return instance;
    }
}
